package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional

public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper mapper;
    private  UserBean loginUser;
    @Override
    public UserBean login(String account, String pwd) {

        loginUser=mapper.login(account,pwd);
        return mapper.login(account,pwd) ;
    }

    @Override
    public boolean add(UserBean userBean) {
        UserBean checkUser=mapper.checkName(userBean);
        if (checkUser==null){
            mapper.add(userBean);
            return true;
        }
        return false;
    }

    @Override
    public void del(int id) {
        mapper.del(id);

    }

    @Override
    public void update(int id, String grade) {
        mapper.update(id,grade);

    }

    @Override
    public UserBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public void updatePwd(int id, String pwd) {
        mapper.updatePwd(id,pwd);

    }

    @Override
    public List<UserBean> findByItem(String grade) {
        if (grade.equals("不限")){
            grade = null;
        }
        List<UserBean>list=mapper.findByItem(grade);
        return list ;
    }
}
